package servlet;

import user.Book;
import util.JDBC;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;

public class ByISBNServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String ISBN = request.getParameter("ISBN");
        ConnectServlet conn = new ConnectServlet();
        conn.doGet(request, response);
        Connection connection = conn.getConnection(); //获取连接
        List<Book> list = null;
        try {
            list = JDBC.getBookByISBN(ISBN, connection);
            connection.close();
            JDBC.release();
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("book", list);
        request.getRequestDispatcher("result.jsp").forward(request, response);
    }
}
